# -*- coding: utf-8 -*-

from google.appengine.ext.webapp import template

def dateformat(date,arg):
  format_string={
                 'ym':'%Y年%m月',
                 'ymd':'%Y年%m月%d日',
                 'md':'%m月%d日',
                 }
  try:
    return date.strftime(format_string[arg])
  except (KeyError,AttributeError):
    return None

def rssdateformat(date):
  try:
    return "%s, %02d %s %04d %02d:%02d:%02d GMT" % (
            ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"][date.weekday()],
            date.day,
            ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date.month-1],
            date.year, date.hour, date.minute, date.second)
  except:
    return None

# Register the filter functions with Django
register = template.create_template_register()
register.filter(dateformat)
register.filter(rssdateformat)